package com.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.Consult;
import com.exam.service.ConsultService;
import com.exam.util.ApiResultHandler;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @Description:
 * @Company：
 * @Author:
 * @Date: 2022/4/29 21:46
 * @Version 1.0
 */
@RestController
public class ConsultController {
    @Resource
    private ConsultService consultService;

    @PostMapping("/addConsult")
    public ApiResult add(@RequestBody Consult consult){
        consult.setCreateDate(new Date());
        return ApiResultHandler.success(consultService.add(consult));
    }

    @PutMapping("/updateConsult")
    public ApiResult update(@RequestBody Consult consult){
        return ApiResultHandler.success(consultService.update(consult));
    }


    @GetMapping("/consults")
    public ApiResult findAll( Integer page,  Integer size,HttpSession session,String teacherName,Integer userId,String userName){
        Page<Consult> teacherPage = new Page<>(page,size);
        IPage<Consult> teacherIPage = consultService.findAll(teacherPage,userId,teacherName,userName);
        return ApiResultHandler.buildApiResult(200,"查询所有咨询记录",teacherIPage);
    }


    @GetMapping("/consult/{id}")
    public ApiResult findById(@PathVariable("id") Integer id){
        return ApiResultHandler.success(consultService.findById(id));
    }
}
